package com.itheima.d09_jdk8_localdate;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 目标：掌握LocalDate类的常用方法
 */
public class LocalDateTimeTest {

    public static void main(String[] args) {
        //1.获取当前时间对象
        LocalDateTime now = LocalDateTime.now();

        //2.获取当前日期的信息：年、月、日（getXXX）
        System.out.println("年："+now.getYear());
        System.out.println("月："+now.getMonthValue());
        System.out.println("日："+now.getDayOfMonth());
        System.out.println("周日："+now.getDayOfWeek());
        System.out.println("年日："+now.getDayOfYear());

        System.out.println("时："+now.getHour());
        System.out.println("分："+now.getMinute());
        System.out.println("秒："+now.getSecond());
        System.out.println("纳秒："+now.getNano());

        //3.直接修改当前日期：年、月、日（withXXX）
        LocalDateTime localDate = now.withYear(2026);
        System.out.println("设置新的年："+localDate);
        LocalDateTime localDate2 = now.withMonth(12);
        System.out.println("设置新的月："+localDate2);

        LocalDateTime localDate3 = now.withHour(5);
        System.out.println("设置新的小时："+localDate3);
        LocalDateTime localDate4 = now.withMinute(12);
        System.out.println("设置新的分钟："+localDate4);

        //4.添加指定的时间：年、月、日（plusXXX）
        System.out.println("一个月前："+now.plusHours(-1));
        System.out.println("一个月前："+now.plusMonths(-1));

        //5.减少指定的时间：年、月、日（minusXXX）
        System.out.println("一个月前："+now.minusHours(30));
        System.out.println("一个月前："+now.minusDays(30));


        //6.比较判断时间的先后：isBefore、isAfter、isEqual
        /*LocalDateTime liang = LocalDateTime.of(22, 22, 22,11,11,11);
        LocalDateTime xiang = LocalDateTime.of(4, 11, 11,11,11,11);

        if(liang.isAfter(xiang)){
            System.out.println("亮小");
        }else{
            System.out.println("亮大");
        }*/


        //7.从LocalDateTime中获取LocalDate和LocalTime
        System.out.println("日期："+now.toLocalDate());
        System.out.println("时间："+now.toLocalTime());
    }
}








